package com.jhgsys.internal.hazard.service.impl;

import com.jhgsys.internal.hazard.entity.HazardExamineDtlConfig;
import com.jhgsys.internal.hazard.mapper.HazardExamineDtlConfigMapper;
import com.jhgsys.internal.hazard.service.IHazardExamineDtlConfigService;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 *  Service实现
 *
 * @author Lujiachen
 * @date 2024-08-13 08:57:26
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class HazardExamineDtlConfigServiceImpl extends ServiceImpl<HazardExamineDtlConfigMapper, HazardExamineDtlConfig> implements IHazardExamineDtlConfigService {

    /**
     * 查询（分页）
     * @author Lujiachen
     * @date 2024-08-13 08:57:26
     * @param request QueryRequest
     * @param hazardExamineDtlConfig hazardExamineDtlConfig
     * @return IPage<HazardExamineDtlConfig>
    */
    @Override
    public IPage<HazardExamineDtlConfig> findHazardExamineDtlConfigPage(QueryRequest request, HazardExamineDtlConfig hazardExamineDtlConfig) {
        LambdaQueryWrapper<HazardExamineDtlConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HazardExamineDtlConfig::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<HazardExamineDtlConfig> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author Lujiachen
     * @date 2024-08-13 08:57:26
     * @param hazardExamineDtlConfig hazardExamineDtlConfig
     * @return List<HazardExamineDtlConfig>
     */
    @Override
    public List<HazardExamineDtlConfig> findHazardExamineDtlConfigList(HazardExamineDtlConfig hazardExamineDtlConfig) {
	    LambdaQueryWrapper<HazardExamineDtlConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HazardExamineDtlConfig::getDeletedFlg, 0);
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author Lujiachen
    * @date 2024-08-13 08:57:26
    * @param id
    * @return HazardExamineDtlConfig
    */
    @Override
    public HazardExamineDtlConfig findHazardExamineDtlConfigById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author Lujiachen
     * @date 2024-08-13 08:57:26
     * @param hazardExamineDtlConfig hazardExamineDtlConfig
     */
    @Override
    @Transactional
    public void createHazardExamineDtlConfig(HazardExamineDtlConfig hazardExamineDtlConfig) {
        hazardExamineDtlConfig.setCreatedTime(new Date());
        this.save(hazardExamineDtlConfig);
    }

    /**
     * 修改
     * @author Lujiachen
     * @date 2024-08-13 08:57:26
     * @param hazardExamineDtlConfig hazardExamineDtlConfig
     */
    @Override
    @Transactional
    public void updateHazardExamineDtlConfig(HazardExamineDtlConfig hazardExamineDtlConfig) {
        hazardExamineDtlConfig.setUpdatedTime(new Date());
        this.saveOrUpdate(hazardExamineDtlConfig);
    }

    /**
     * 逻辑删除
     * @author Lujiachen
     * @date 2024-08-13 08:57:26
     * @param hazardExamineDtlConfig hazardExamineDtlConfig
     * @param hazardExamineDtlConfigIds hazardExamineDtlConfigIds
     */
    @Override
    @Transactional
    public void deleteHazardExamineDtlConfig(HazardExamineDtlConfig hazardExamineDtlConfig,String hazardExamineDtlConfigIds) {
        List<String> list = Arrays.asList(hazardExamineDtlConfigIds.split(StringPool.COMMA));
        this.baseMapper.update(hazardExamineDtlConfig,new LambdaQueryWrapper<HazardExamineDtlConfig>().in(HazardExamineDtlConfig::getExamineDtlConfigId,list));
	}

    /**
    * 物理删除
    * @author Lujiachen
    * @date 2024-08-13 08:57:26
    * @param hazardExamineDtlConfigIds hazardExamineDtlConfigIds
    */
    @Override
    @Transactional
    public void physicallyDeleteHazardExamineDtlConfig(String hazardExamineDtlConfigIds) {
        List<String> list = Arrays.asList(hazardExamineDtlConfigIds.split(StringPool.COMMA));
        LambdaQueryWrapper<HazardExamineDtlConfig> wapper = new LambdaQueryWrapper<>();
        wapper.in(HazardExamineDtlConfig::getExamineDtlConfigId,list);
        this.remove(wapper);
    }

    @Override
    public List<HazardExamineDtlConfig> findHazardExamineDtlConfigListByExamineConfigId(HazardExamineDtlConfig hazardExamineDtlConfig) {
        LambdaQueryWrapper<HazardExamineDtlConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HazardExamineDtlConfig::getDeletedFlg, 0);
        queryWrapper.eq(HazardExamineDtlConfig::getExamineConfigId, hazardExamineDtlConfig.getExamineConfigId());
        // TODO 设置查询条件
        return this.baseMapper.selectList(queryWrapper);
    }
}
